package ar.com.angrymachine.hunter.activities;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Vector;

import ar.com.angrymachine.hunter.Activity;
import ar.com.angrymachine.hunter.Game;
import ar.com.angrymachine.hunter.GraphicStyles;
import ar.com.angrymachine.hunter.Locale;
import ar.com.angrymachine.hunter.HunterResourceManager;

public class BossAltarActivity extends IncrementalActivity
{
    private int defileTime;
    
    public BossAltarActivity(int defileTime)
    {
        this.defileTime = defileTime;
    }
    
    public String getDescription()
    {
        if(isCompleted())
        {
            return getName();
        }
        else
        {
            return Locale.percentageLabel(getName(), currentTime, getCompletionTime());
        }
    }
    
    private String getName()
    {
   		return Locale.BOSS_ALTAR;
    }

    public String getActionText()
    {
        if(isCompleted())
        {
            return Locale.DESTROYED;
        }
        else
        {
            if(isRunning())
            {
                return Locale.DEFILING;
            }
            else
            {
                return Locale.DEFILE;
            }
        }
    }    

    public void paint(Graphics g, Rectangle activityArea)
    {
        GraphicStyles.paintDefaultActivity(g, this, activityArea, HunterResourceManager.getImage("altar.png"));
    }

    public void onFinished()
    {
        Vector activities = Game.current.currentLevel.activities;
        // HACK: remove boss
        for (int i = 0; i < activities.size();)
        {
            boolean removed = false;
            Activity a = (Activity) activities.elementAt(i);
            if(a instanceof FightActivity)
            {
                FightActivity fa = (FightActivity) a;
                if(fa.monster.getLevel() <= 100)
                {
                    activities.removeElementAt(i);
                    removed = true;
                    //TODO: mark the quest as complete, if applicable
                    //Game.current.player.won = true;
                }
            }
            else
            if(a instanceof SlumberActivity)
            {
                SlumberActivity fa = (SlumberActivity) a;
                if(fa.monster.getLevel() <= 100)
                {
                    activities.removeElementAt(i);
                    removed = true;
                }               
            }
            if(!removed)
            {
                i++;
            }
        }
    }

    protected int getCompletionTime()
    {
        return defileTime;
    }

    protected boolean onCompletion()
    {
        return true;
    }
}
